<template>
  <div class="moneyList">
    <div class="top">
      <div class="time pad">
        <span class="label">营业执照号：</span>
        <el-input v-model="filter.businessLicense" placeholder="请输入内容"></el-input>
      </div>
      <div class="time pad">
        <span class="label">商户账户名称：</span>
        <el-input v-model="filter.merchantName" placeholder="请输入内容"></el-input>
      </div>
      <div class="time pad">
        <span class="label">店铺名称：</span>
        <el-input v-model="filter.shopName" placeholder="请输入内容"></el-input>
      </div>
      <div class="time pad">
        <span class="label">创建时间：</span>
        <el-date-picker v-model="TimeArr" type="daterange" value-format="yyyy-MM-dd" @change="getTimeArr"
          range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </div>
      <div class="time pad">
        <span class="label">日常消费账户状态：</span>
        <el-select v-model="filter.everydayStatus" placeholder="请选择">
          <el-option v-for="item in consumeLs" :key="item.id" :label="item.value" :value="item.id">
          </el-option>
        </el-select>
      </div>
      <div class="time pad">
        <span class="label">存管账户账户状态：</span>
        <el-select v-model="filter.depositStatus" placeholder="请选择">
          <el-option v-for="item in depositoryLs" :key="item.id" :label="item.value" :value="item.id">
          </el-option>
        </el-select>
      </div>
      <div class="time pad">
        <span class="label">管辖区域：</span>
        <el-select v-model="filter.areaId" placeholder="请选择">
          <el-option v-for="item in areaSelect" :key="item.id" :label="item.value" :value="item.id">
          </el-option>
        </el-select>
      </div>
      <!-- <div class="time pad">
        <span class="label">商户编号：</span>
        <el-input
          v-model="filter.merchantId"
          placeholder="请输入内容"
        ></el-input>
      </div> -->
      <div class="btn pad">
        <el-button @click="setReset">重置</el-button>
        <el-button type="primary" @click="search">查询</el-button>
      </div>
    </div>
    <div class="main">
      <div class="main_top">
        <div class="lef_box">
          <!-- <el-button size="small" type="primary" @click="add">新建</el-button>
          <div class="lef">
            <div
              class=""
              v-for="item in type"
              :class="['list', currentNavtab == item.id ? 'active' : '']"
              :key="item.id"
              :value="item.id"
              @click="handleTab(item.id)"
            >
              {{ item.value }}
            </div>
          </div> -->
        </div>
        <export-excel-button title="第三方商户进件" action="/entry/v1/fund/merchantFundAccountExport" :params="ExportParams" />
      </div>
      <ex-table ref="table" :loading="loading" :table-column="tableColumn" :table-data="tableData"
        @pageSizeChange="handleSizeChange" @currentPageChange="handleCurrentChange">
        <template v-slot:everydayDict="{ scope }">
          <p v-for="(item,index) in scope.row.everydayDict" :key="index">{{item}}</p>
        </template>
        <template v-slot:depositEntryDict="{ scope }">
          <p v-for="(item,index2) in scope.row.depositEntryDict" :key="index2">{{item}}</p>
        </template>
        <template v-slot:operate="{ scope }">
          <!-- <el-button @click="lookDetailys(scope.row)" size="small" plain v-if="
              scope.row.everydayDict != ('待运营审核' || '申请驳回') &&
              scope.row.depositEntryDict != ('待运营审核' || '申请驳回')
            ">查看详细</el-button>
          <el-button @click="lookDetailys(scope.row)" size="small" plain type="warning" v-if="
              scope.row.everydayDict == ('待运营审核' || '申请驳回') ||
              scope.row.depositEntryDict == ('待运营审核' || '申请驳回')
            ">审核资料</el-button>
          <el-button @click="handleMessage(scope.row.merchantId)" size="small"
            v-if="scope.row.everydayEntryStatus == 'FAIL_SIGN'||scope.row.depositEntryStatus == 'FAIL_SIGN'" type="primary">重新推送签约短信</el-button> -->
          <el-button @click="lookDetailys(scope.row,1)">日常消费账户详情</el-button>
          <el-button @click="lookDetailys(scope.row,2)" :loading="cgLoading">存管账户详情</el-button>
        </template>
      </ex-table>
    </div>
  </div>
</template>
<script>
  // components
  // import FilterSearch from './components/newIncreaseVerify/FilterSearch'
  // api
  import ExportExcelButton from "@/components/ExportExcelButton/index";
  import {
    getMoneyList,
    adminDict,
    deleteList,
    ysSendSignSms,
    ysDepositInfo,
  } from "@/api/moneyManagement";
  import {
    userAreaSelect,
  } from "@/api/common";
  // mixins
  import handlePageMixin from "@/mixins/handlePageMixin";

  export default {
    name: "moneyList",
    components: {
      ExportExcelButton,
    },
    mixins: [handlePageMixin],
    data() {
      return {
        cgLoading: false,
        loading: false,
        consumeLs: [], //日常下拉
        depositoryLs: [], //存管下拉
        type: [{
            id: "",
            value: "全部"
          },
          {
            id: "1",
            value: "等待审核"
          },
          {
            id: "2",
            value: "创建失败"
          },
          {
            id: "3",
            value: "创建成功"
          },
        ],
        tableColumn: [{
            prop: "areaName",
            label: "管辖区域",
            width: "130"
          },
          {
            prop: "merchantName",
            label: "商户账号名称",
            width: "200"
          },
          {
            prop: "shopName",
            label: "店铺名称",
            width: "130"
          },
          {
            prop: "businessLicense",
            label: "营业执照",
            width: "200"
          },
          {
            prop: "everydayDict",
            label: "日常消费账户",
            slotName: "everydayDict",
            slot: true,
            width: 200
          },
          {
            prop: "depositEntryDict",
            label: "存管账户",
            slotName: "depositEntryDict",
            slot: true,
            width: 200,
          },
          {
            prop: "updateTime",
            label: "时间",
            width: "180"
          },
          {
            label: "操作",
            slot: true,
            slotName: "operate",
            fixed: "right",
            width: "340",
          },
        ],
        tableData: [],
        TimeArr: [],
        filter: {
          areaId: '', //区域
          businessLicense: "", //营业执照号
          merchantName: "", //商户名称
          shopName: "", //店铺名称
          createStartTime: "", //创建时间--开始
          createEndTime: "", //创建时间--结束
          everydayStatus: "", //日常收款账户状态   merchant_fund_entry_status
          depositStatus: "", //存管账户状态 merchant_fund_entry_status         -1 未开通
        },
        value: "",
        time: "",
        currentNavtab: 0,
        areaSelect: [], //区域下拉
      };
    },
    computed: {
      ExportParams() {
        const {
          id: ticketId
        } = this;
        const params = {
          ...this.pageOptions,
          ...this.filter,
        };
        return params;
      },
    },
    created() {
      this.getconsumeLs();
      this.getdepositoryLs();
      this.getUserAreaSelect()
      this.getList();
    },
    methods: {
      getconsumeLs() {
        //获取日常状态下拉字典
        const params = {
          dictType: "merchant_fund_entry_status",
        };
        adminDict(params).then((res) => {
          var arr = [{
            id: "",
            value: "全部",
          }, ];
          this.consumeLs = arr.concat(res.result[0].dictList);
        });
      },
      getdepositoryLs() {
        //获取存管状态下拉字典
        var params = {
          dictType: "merchant_fund_entry_status",
        };
        adminDict(params).then((res) => {
          var arr = [{
              id: "",
              value: "全部",
            },
            // {
            //   id: "-1",
            //   value: "未开通",
            // },
          ];
          this.depositoryLs = arr.concat(res.result[0].dictList);
        });
      },
      getUserAreaSelect() {
        //查询用户区域下拉框
        userAreaSelect().then((res) => {
          var arr = [{
            id: "",
            value: "全部",
          }, ];
          this.areaSelect = arr.concat(res.result);
        });
      },
      //列表
      getList() {
        this.loading = true;
        const params = {
          ...this.pageOptions,
          ...this.filter,
        };
        getMoneyList(params)
          .then((res) => {
            const {
              total,
              records
            } = res.result;
            records.forEach((item) => {
              // 日常消费账户判断
              let arr = item.everydayAccount.split(',');
              item.everydayDict = arr;
              // if (item.everydayEntryStatus == "AUDITED") {
              //   item.everydayDict = item.everydayAccount;
              // } else {
              //   item.everydayDict = item.everydayEntryStatusDict;
              // }
              //存管账户判断
              let arrTwo = item.depositAccount.split(',');
              item.depositEntryDict = arrTwo;
              // if (item.depositEntryStatus == "AUDITED") {
              //   item.depositEntryDict = item.depositAccount;
              // } else if (item.depositEntryStatus != "AUDITED") {
              //   item.depositEntryDict = item.depositEntryStatusDict;
              // } else {
              //   item.depositEntryDict = "未开通";
              // }
            });

            this.$refs.table.pageOptions.total = total;
            this.tableData = records;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      //获取时间
      getTimeArr(value) {
        this.filter.createStartTime = this.TimeArr[0];
        this.filter.createEndTime = this.TimeArr[1];
      },
      //切换选项
      handleTab(id) {
        console.log("id", id), (this.currentNavtab = id);
        this.filter.status = id;
        this.getList();
      },
      //重置
      setReset() {
        this.TimeArr = [];
        this.filter.businessLicense = "";
        this.filter.merchantName = "";
        this.filter.shopName = "";
        this.filter.createStartTime = "";
        this.filter.createEndTime = "";
        this.filter.everydayStatus = "";
        this.filter.depositStatus = "";
        this.filter.areaId = '';
        this.pageOptions.pageNum = 1;
        this.$refs.table.pageOptions.pageNum = 1;
        this.getList();
      },
      //搜索
      search() {
        this.pageOptions.pageNum = 1;
        this.$refs.table.pageOptions.pageNum = 1;
        this.getList();
      },
      //新建
      add() {
        this.$router.push({
          path: "/moneyManagement/add-money",
          query: {
            type: "add",
          },
        });
      },
      //查看
      lookDetail(data) {
        var id = data.id;
        var orderNo = data.orderNo;
        var merchantNo = data.merchantNo;
        var status = data.status;
        if (status == 1 || status == 2) {
          this.$router.push({
            path: "/moneyManagement/add-money",
            query: {
              fundId: id,
              type: "edit",
              orderNo: orderNo,
              merchantNo: merchantNo,
            },
          });
        } else if (status == 3) {
          this.$router.push({
            path: "/moneyManagement/money-detail",
          });
        }
      },
      lookDetailys(e, type) {
        if (type == 2) { //存管
          this.cgLoading = true
          ysDepositInfo(e.merchantId).then((res) => {
            this.cgLoading = false
            this.$router.push({
              path: "/merchants/incoming-detail",
              query: {
                // entryStatus: e.entryStatus,
                merchantId: e.merchantId,
                fundAccountSettleType: type
              },
            });
          }).catch(() => {
            this.cgLoading = false
          })
        } else { //日常
          this.$router.push({
            path: "/merchants/incoming-detail",
            query: {
              // entryStatus: e.entryStatus,
              merchantId: e.merchantId,
              fundAccountSettleType: type
            },
          });
        }
      },
      //管理
      toManagement(data) {
        var fundId = data.id;
        var merchantNo = data.merchantNo;
        this.$router.push({
          path: "/moneyManagement/money-detail",
          query: {
            fundId: fundId,
            merchantNo: merchantNo,
          },
        });
      },
      //删除资金账户
      getDelete(id) {
        this.$confirm("是否删除?", "提示", {
            confirmButtonText: "删除",
            cancelButtonText: "否",
            type: "warning",
          })
          .then(() => {
            deleteList(id)
              .then((res) => {
                const {} = res.result;
                this.getList();
                this.$message({
                  message: "删除成功",
                  type: type,
                  duration: 1500,
                });
              })
              .finally(() => {
                this.loading = false;
              });
          })
          .catch(() => {});
      },
      //推送短信
      handleMessage(merchantId) {
        var params = {
          merchantId: merchantId,
        };
        ysSendSignSms(params).then((res) => {
          if (res.code == 200) {
            this.$message.success("发送成功");
          }
        });
      },
    },
  };

</script>
<style lang="scss" scoped>
  @import "./style/incomingParts";

  .time ::v-deep .el-input {
    width: 200px;
  }

  .el-select .el-input {
    width: 130px;
  }

  .first_box {
    ::v-deep :nth-child(1).el-input__inner {
      width: 100px;
    }

    ::v-deep :nth-child(2).el-input__inner {
      width: 200px;
    }
  }

  .input-with-select .el-input-group__prepend {
    background-color: #fff;
  }

</style>
